<template>
  <div>
    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
      <div class="widget am-cf">
        <div class="widget-head am-cf">
            <div class="widget-title am-fl">展示设置</div>

        </div>
        <div class="widget-body  am-fr">
          <div class="am-u-sm-12">
            <el-table
              :data="tableData"
              border
              stripe
              style="min-width: 100%">
              <el-table-column
                prop="areaTeamName"
                label="区域"
                min-width="100">
              </el-table-column>
              <el-table-column
                prop="studentPhoneNo"
                label="显示期数"
                min-width="300">
                <template scope="scope">
                  <div v-if="scope.row.periods">
                    <span v-for="item in scope.row.periods"> {{item.periodName}} </span>
                  </div>

                </template>
              </el-table-column>
              <el-table-column
                label="操作"
                min-width="100" align="center">
                <template scope="scope">
                    <div>
                       <el-button size="small" @click="$router.push('/main/online/editShowSetting?areaTeamId='+ scope.row.areaTeamId)">编辑</el-button>
                    </div>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="am-u-lg-12 am-cf">
            <div class="am-fr">
              <pagination v-bind:total="total" v-bind:pageNo="pageNo" v-bind:pageSize="pageSize"
                          @paging="loadTableData"/>
            </div>
          </div>
        </div>
      </div>
    </div>

  </div>
</template>

<script>

  import Pagination from '../base/Pagination'
  import io from '../../lib/io/index'

  export default{
    data: function () {
      return {
        multipleSelection: [],
        examPaperIds: [],
        measurementId: '',
        tableData: [],
        total: 0,
        pageSize: 10,
        pageNo: 1,
        query:{
            areaTeamId : window.config.areaTeams[0] && window.config.areaTeams[0].areaTeamId || '' ,
        }
      }
    },
    components: {
      Pagination
    },
    mounted: function () {
      $(window).smoothScroll()
    },
    created: function () {
      this.loadTableData(1)
    },
    computed:{
        areaTeams: function () {
        var options = ( this.$root.config.areaTeams || [] )
            .map(function (item) {
            return {value: item.areaTeamId, text: item.name}
            })
        return options
        },
    },
    methods: {
      loadTableData: function (pageNo) {
        var _this = this
        _this.pageNo = pageNo || _this.pageNo || 1
        io.post(io.courseDisplayConfigList, {
          areaTeamId:"",
          pageNo: _this.pageNo,
          pageSize: _this.pageSize,
        }, function (ret) {
          if (ret.success) {
            // _this.total = ret.data.total
            let tableData = []
            _this.areaTeams.forEach(item =>{

              let dataItem  = null
              for(var i = 0 ; i < ret.data.length ; i++ ){
                if(item.value == ret.data[i].areaTeamId ){
                  dataItem = ret.data[i]
                  break
                }
              }


              if(!dataItem){
                tableData.push({
                  areaTeamName:item.text,
                  areaTeamId:item.value,
                  periods:[]
                })
              }else{
                tableData.push(dataItem)
              }
            })

            _this.tableData = tableData
          } else {
            _this.$alert(ret.desc)
          }
        })
      },
    }
  }
</script>
<style scoped lang="less">
  .red {
    color: red;
  }
  .content-tooltip {
    unicode-bidi: embed;
    white-space: pre;
    font-size: 14px;
    line-height: 1.5;
  }
</style>
